﻿using System.Xml;
using NUnit.Framework;

namespace PhotoFramePublishingPlugin.Tests
{
    [TestFixture]
    public class PersistHelperTests
    {
        [Test]
        public void GivenBlankDocument_ReadDestination_ReturnsNull()
        {
            XmlDocument persistXml = new XmlDocument();
            
            string actual = PersistHelper.ReadDestination(persistXml);
            Assert.IsNull(actual);
        }

        [Test]
        public void GivenInitializedDocument_ReadDestination_ReadsDefaultValue()
        {
            XmlDocument persistXml = new XmlDocument();
            PersistHelper.InitializeDocument(persistXml);

            string actual = PersistHelper.ReadDestination(persistXml);
            Assert.IsEmpty(actual);
        }

        [Test]
        public void GivenInitializedDocument_AndWriteDestination_ReadDestination_ReadsCorrectValue()
        {
            XmlDocument persistXml = new XmlDocument();
            PersistHelper.InitializeDocument(persistXml);

            const string expected = @"D:\Temp";
            PersistHelper.WriteDestination(persistXml, expected);

            string actual = PersistHelper.ReadDestination(persistXml);
            Assert.AreEqual(expected, actual);
        }

        [Test]
        public void GivenInitializedDocument_ReadShouldShortenFilenames_ReadsDefaultValue()
        {
            XmlDocument persistXml = new XmlDocument();
            PersistHelper.InitializeDocument(persistXml);

            bool actual = PersistHelper.ReadShouldShortenFileNames(persistXml);
            Assert.IsFalse(actual);
        }

        [Test]
        public void GivenInitializeDocument_AndWriteShouldShortenFilenames_ReadShouldShortenFilenames_ReadsCorrectValue()
        {
            XmlDocument persistXml = new XmlDocument();
            PersistHelper.InitializeDocument(persistXml);

            const bool expected = true;
            PersistHelper.WriteShouldShortenFileNames(persistXml, expected);

            bool actual = PersistHelper.ReadShouldShortenFileNames(persistXml);
            Assert.AreEqual(expected, actual);
        }

        [Test]
        public void GivenInitializedDocument_ReadShouldAddBorders_ReadsDefaultValue()
        {
            XmlDocument persistXml = new XmlDocument();
            PersistHelper.InitializeDocument(persistXml);

            bool actual = PersistHelper.ReadShouldAddBorders(persistXml);
            Assert.AreEqual(false, actual);
        }

        [Test]
        public void GivenInitializedDocument_AndWriteShouldAddBordersTrue_ReadShouldAddBorders_ReadsCorrectValue()
        {
            XmlDocument persistXml = new XmlDocument();
            PersistHelper.InitializeDocument(persistXml);

            const bool expected = true;
            PersistHelper.WriteShouldAddBorders(persistXml, expected);

            bool actual = PersistHelper.ReadShouldAddBorders(persistXml);
            Assert.AreEqual(expected, actual);
        }

        [Test]
        public void GivenInitializedDocument_AndWriteShouldAddBordersFalse_ReadShouldAddBorders_ReadsCorrectValue()
        {
            XmlDocument persistXml = new XmlDocument();
            PersistHelper.InitializeDocument(persistXml);

            const bool expected = false;
            PersistHelper.WriteShouldAddBorders(persistXml, expected);

            bool actual = PersistHelper.ReadShouldAddBorders(persistXml);
            Assert.AreEqual(expected, actual);
        }
    }
}
